Type LibraryLoader
	
	Field currentLibrary:Library
	Field observers:TList
	Field strategy:LibraryLoaderStrategy

	Method New()
		observers = New TList
	End Method

	Method load:Library()
		currentLibrary = New Library
		If strategy <> Null Then
			strategy.Load(Self)
		End If
		Local lib:Library = currentLibrary
		currentLibrary  = Null
		Return lib
	End Method
	
	Method addObserver(o:LibraryLoaderObserver)
		If observers.Contains(Object(o)) = False Then
			observers.addLast(o)
		End If
	End Method
	
	Method removeObserver(o:LibraryLoaderObserver)
		observers.Remove(Object(o))
	End Method
	
	Method clearObservers()
		observers.Clear()
	End Method	
	
	Method NotifyObservers()
		'Print strategy.getProgress() + ": " + strategy.getStatusMessage()
		Local o:Object
		For o = EachIn observers
			LibraryLoaderObserver(o).Update(strategy)
		Next
	End Method
	
	Method addPlaylist(p:Playlist)
		If currentLibrary = Null Then
			Return
		End If
		currentLibrary.playlists.AddLast(p)
		NotifyObservers()
	End Method
	
	Method addTrackInformation(t:TrackInformation)
		If currentLibrary = Null Then
			Return
		End If
		currentLibrary.tracks.AddLast(t)
		NotifyObservers()
	End Method

End Type
